package com.naire.modul.customer.service;

import java.util.ArrayList;
import java.util.List;

import net.common.service.GeneralService;
import net.common.util.XMLHandler;

import org.dom4j.Element;
import org.dom4j.Node;

import com.naire.modul.customer.dao.CustomerDao;
import com.naire.modul.customer.dao.impl.CustomerDaoImpl;
import com.naire.modul.customer.vo.FieldVo;

/**
 * 客户门店机构定义
 * 
 * @author Administrator
 * 
 */
public class CustomerDefinedService extends GeneralService {

	private List<FieldVo> fields = null;
	private Integer cust_id;

	@Override
	public void execute() throws Exception {
		fields = new ArrayList<FieldVo>();
		CustomerDao dao = new CustomerDaoImpl();
		String text = dao.findText(cust_id);
		XMLHandler xml = new XMLHandler(text);
		List<Node> nodes = xml.selectNodes("fields/field");
		for(Node n : nodes) {
			Element e = (Element)n;
			FieldVo fv = new FieldVo();
			fv.setId(Integer.parseInt(e.attributeValue("id")));
			fv.setLength(Integer.parseInt(e.attributeValue("length")));
			fv.setName(e.attributeValue("name"));
			fv.setType(e.attributeValue("type"));
			fields.add(fv);
		}
	}

	public List<FieldVo> getFields() {
		return fields;
	}

	public void setCust_id(Integer cust_id) {
		this.cust_id = cust_id;
	}

}
